package org.dromara.comm.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dromara.comm.domain.AsLabel;
import org.dromara.comm.domain.AsLeaveIdle;
import org.dromara.comm.domain.AsLeaveIdleImage;
import org.dromara.comm.domain.AsUserLeaveIdle;
import org.dromara.comm.service.AsLeaveIdleImageService;
import org.dromara.comm.service.AsLeaveIdleService;
import org.dromara.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/asLeaveIdle")
@Tag(name = "闲置物品管理")
public class AsLeaveIdleController {

    @Autowired
    private AsLeaveIdleService asLeaveIdleService;

    @Autowired
    private AsLeaveIdleImageService asLeaveIdleImageService;

    @Operation(summary = "获取所有闲置商品")
    @GetMapping("/selectAsLeaveIdle")
    public Page<AsLeaveIdle> selectAsLeaveIdle(AsLeaveIdle asLeaveIdle, Pageable pageable) {
        return asLeaveIdleService.selectAsLeaveIdle(asLeaveIdle,pageable);
    }


    @Operation(summary = "获取所有闲小程序置物品")
    @GetMapping("/all")
    public List<AsLeaveIdle> getAllDigitalToys() {
        return asLeaveIdleService.getAllDigitalToys();
    }

    @Operation(summary = "根据分类获取闲置物品")
    @GetMapping("/category/{category}")
    public List<AsLeaveIdle> getDigitalToysByCategory(@PathVariable String category) {
        return asLeaveIdleService.getDigitalToysByCategory(category);
    }

    @Operation(summary = "闲置详细")
    @PostMapping("/details")
    public List<AsLeaveIdle> details(@RequestBody  AsLeaveIdle asLeaveIdle) {
        return asLeaveIdleService.details(asLeaveIdle);
    }

    @Operation(summary = "发布")
    @PostMapping("/insertAsLeaveIdleImages")
    public void insertAsLeaveIdleImages(@RequestBody AsLeaveIdle asLeaveIdle, AsLeaveIdleImage asLeaveIdleImage,List<AsLabel> labelIds) {
        asLeaveIdleService.insertAsLeaveIdleImages(asLeaveIdle, asLeaveIdleImage, labelIds);
    }

    @Operation(summary = "编辑")
    @PostMapping("/updateAsLeaveIdleImages")
    public void updateAsLeaveIdleImages(@RequestBody AsLeaveIdle asLeaveIdle, AsLeaveIdleImage asLeaveIdleImage,List<AsLabel> labelIds) {
        asLeaveIdleService.updateAsLeaveIdleImages(asLeaveIdle, asLeaveIdleImage, labelIds);
    }

    @Operation(summary = "下架")
    @PostMapping("/updateState")
    public void updateState(@RequestBody AsLeaveIdle asLeaveIdle) {
        asLeaveIdleService.updateState(asLeaveIdle);
    }

    @Operation(summary = "删除")
    @GetMapping("/deleteIsDelete")
    public void deleteIsDelete(@RequestParam("id") Integer id) {
        asLeaveIdleService.deleteIsDelete(id);
    }

    @Operation(summary = "查询我的发布")
    @GetMapping("/selectAsMyRelease")
    public Map<String, Object> selectAsMyRelease(AsLeaveIdle asLeaveIdle, Pageable pageable) {
        return asLeaveIdleService.selectAsMyRelease(asLeaveIdle, pageable);
    }

    @Operation(summary = "修改上下架状态")
    @PostMapping("/updateStates")
    public void updateStates(@RequestBody AsLeaveIdle asLeaveIdle) {
        asLeaveIdleService.updateStates(asLeaveIdle);
    }

    @Operation(summary = "修改删除状态")
    @PostMapping("/updateIsDelete")
    public void updateIsDelete(@RequestBody AsLeaveIdle asLeaveIdle) {
        asLeaveIdleService.updateIsDelete(asLeaveIdle);
    }

    @Operation(summary = "添加收藏")
    @PostMapping("/insertCollection")
    public void insertCollection(@RequestBody AsLeaveIdle asLeaveIdle) {
        asLeaveIdleService.insertCollection(asLeaveIdle);
    }

    @Operation(summary = "查询我的收藏")
    @GetMapping("/selectAsUserLeaveIdle")
    public List<Object> selectAsUserLeaveIdle(AsUserLeaveIdle asUserLeaveIdle) {
        return asLeaveIdleService.selectAsUserLeaveIdle(asUserLeaveIdle);
    }

    @Operation(summary = "上传闲置图片")
    @PostMapping("/asLeaveIdleImages")
    public void insertAsLeaveIdleImages(@RequestBody List<AsLeaveIdleImage> asLeaveIdleImages, AsLeaveIdle asLeaveIdle) {
        asLeaveIdleImageService.insertAsLeaveIdleImages(asLeaveIdleImages, asLeaveIdle);
    }

    @Operation(summary = "审核")
    @PostMapping("/updateAsLeaveIdState")
    public void updateAsLeaveIdState(@RequestBody AsLeaveIdle asLeaveIdle){
        asLeaveIdle.setStatus(0);
        asLeaveIdleService.updateById(asLeaveIdle);
    }
}
